class Solution {
public:
    vector<int> diStringMatch(string s)
    {
        int n = s.size();
        vector<int>ret(n + 1);
        int left = 0, right = n;

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'I')
            {
                ret[i] = left;
                left++;
            }
            else if (s[i] == 'D')
            {
                ret[i] = right;
                right--;
            }
        }
        ret[n] = left;
        return ret;
    }
};